clear all
use "C:\Users\sagomm\polybox\Shared\Circular Economy\w7_w8_subgroups_stata.dta"
destring, replace

******Install necesarry user-written commands
do "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\Scripts\functions\function_conjoint.do"
do "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\Scripts\functions\function_addplot.do"

*Create Circular Economy Index

* Rescale the variables to be between 0 and 1
egen min_value = min(Price_recoded), by()
egen max_value = max(Price_recoded), by()
gen rescaled_price = (Price_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen min_value = min(Functional_duration_recoded), by()
egen max_value = max(Functional_duration_recoded), by()
gen rescaled_duration = (Functional_duration_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen min_value = min(env_impacts_recoded), by()
egen max_value = max(env_impacts_recoded), by()
gen rescaled_impact = (env_impacts_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen min_value = min(Energy_efficiency_recoded), by()
egen max_value = max(Energy_efficiency_recoded), by()
gen rescaled_energy = (Energy_efficiency_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen min_value = min(Recyclability_recoded), by()
egen max_value = max(Recyclability_recoded), by()
gen rescaled_recycle = (Recyclability_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen min_value = min(Repairability_recoded), by()
egen max_value = max(Repairability_recoded), by()
gen rescaled_repair = (Repairability_recoded - min_value) / (max_value - min_value)
drop min_value max_value

egen cc_index = rowmean(rescaled_duration rescaled_energy rescaled_recycle rescaled_repair)
egen cc_tertiles = cut(cc_index), group(3)
label define tertile_labels 0 "Low circular economy" 1 "Medium circular economy" 2 "High circular economy"
label values cc_tertiles tertile_labels

egen envatt_sd = std(env_attitudes_mean)


label define ce_labels 1 "Low" 2 "Medium" 3 "High circularity"
label values ce_category ce_labels

****************************************************************************

*Interaction: Environmental attitudes and CC Characteristics

****************************************************************************
** Standard Conjoint **
qui reg choice c.rescaled_price##c.envatt_sd  c.rescaled_impact##c.envatt_sd  i.ce_category##c.envatt_sd,  cluster(PubId)
eststo int_lr
************ Circular Economy Index & Environmental Attitudes *******
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Environmental attitudes", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt, replace) 

************ Circular Economy Index & Political ideology *******
qui reg choice c.rescaled_price##i.political_ideology  c.rescaled_impact##i.political_ideology  i.ce_category##i.political_ideology c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(political_ideology=(1(1)3) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Political ideology", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "left" 2 "center" 3 "right", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(polit, replace) 
	
************ Circular Economy Index & Income*******
gen inc = . 
replace inc = 3 if income == "High (> 14'001 CHF)"
replace inc = 2 if income == "Medium (6'001 - 14'000 CHF)"
replace inc = 1 if income == "Low (=< 6'000 CHF)"

label define income_labels 1 "Low" 2 "Medium" 3 "High"
label values inc income_labels

qui reg choice c.rescaled_price##i.inc  c.rescaled_impact##i.inc  i.ce_category##i.inc c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(inc=(1(1)3) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Income", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "low" 2 "medium" 3 "high", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(income, replace) 
	
************ Circular Economy Index & Age *******
qui reg choice c.rescaled_price##i.Age  c.rescaled_impact##i.Age  i.ce_category##i.Age c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(Age=(1(1)4) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Age groups", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "<30" 2 "30-49" 3 "50-59" 4 ">70", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(age, replace) 
	
************ Circular Economy Index & Gender *******
gen gender = . 
replace gender = 1 if Gender == "Female"
replace gender = 2 if Gender == "Male"

label define gender_labels 1 "Female" 2 "Male"
label values gender gender_labels

qui reg choice c.rescaled_price##i.gender  c.rescaled_impact##i.gender  i.ce_category##i.gender c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(gender=(1(1)2) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Gender", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "Female" 2 "Male", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(gender, replace) 

************ Circular Economy Index & Education *******
gen educ = .
replace educ = 1 if Education == 1 | Education == 2 
replace educ = 2 if Education == 3 | Education == 4  | Education == 5 
replace educ = 3 if Education == 6 | Education == 7 


label define educ_labels 1 "Low" 2 "Medium" 3 "High"
label values educ educ_labels


qui reg choice c.rescaled_price##i.educ  c.rescaled_impact##i.educ  i.ce_category##i.educ c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(educ=(1(1)3) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Education", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "low" 2 "medium" 3 "high", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(education, replace) 
	
************ Circular Economy Index & Stated importance of repairability *******
qui reg choice c.rescaled_price##i.importance_repairability  c.rescaled_impact##i.importance_repairability  i.ce_category##i.importance_repairability c.envatt_sd,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(importance_repairability=(1(1)2) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Importance of repairability", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "Not important" 2 "Important", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(importance, replace) 

	
//Make combined interacton figure
grc1leg ///
	envatt ///
	polit ///
	education ///
	income, ///
	row (2) ///
	ysize(10) xsize(35) ///
	graphregion(color(white)) ///
	name(interaction_models1, replace)

gr export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig5_subgroups_combined.png", as(png) ///
	name("interaction_models1") replace	
	
	
grc1leg ///
	age ///
	gender, ///
	row (1) ///
	ysize(10) xsize(35) ///
	graphregion(color(white)) ///
	name(interaction_appendix, replace)

gr export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig5_subgroups_combined.png", as(png) ///
	name("interaction_models1") replace	
	
gr export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig_appendix_1.png", as(png) ///
	name("interaction_appendix") replace	
	
** FIGURE 6: Interaction by Policy Support ***

************ Circular Economy Index & Repairability label *******
qui reg choice c.rescaled_price##c.w8_q34  c.rescaled_impact##c.w8_q34  i.ce_category##c.w8_q34,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(w8_q34=(1(1)5) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Repairability label", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "Opposed" 2 "2" 3 "3" 4 "4" 5 "In favour", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(rep_label, replace) 
	
************ Circular Economy Index & Minimal functional duration label *******
qui reg choice c.rescaled_price##c.w8_q36  c.rescaled_impact##c.w8_q36  i.ce_category##c.w8_q36,  cluster(PubId)
eststo int_lr
loc ylab 0.2(.2).8

est rest int_lr
qui margins, at(w8_q36=(1(1)5) ce_category=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Functional duration label", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(1 "Opposed" 2 "2" 3 "3" 4 "4" 5 "In favour", labsize(small)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(1)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(func_label, replace) 
	
//Make combined interacton figure
grc1leg ///
	rep_label ///
	func_label, ///
	row (1) ///
	graphregion(color(white)) ///
	name(interaction_models2, replace)

gr export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig6_polsupport_interaction.png", as(png) ///
	name("interaction_models2") replace	
	